<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  <meta name="google-site-verification" content="XKEVBvaS3n3qpVoP-hQqQ2XJ9t43pt4B7J1sLZgRJG4" />
  
  
  <title>最佳实践 | 源码编译安装配置 Postgres-XC 集群并用 pg_basebackup 配置 Datanode 热备 | DBKernel - 专注于分享数据库技术</title>
  <meta name="description" content="本文首发于 2016-03-15 19:56:52  注意：本篇文章成文时 Postgres-XC 还未改名为 Postgres-X2 。 1. 下载源码1git clone git@github.com:postgres-x2&#x2F;postgres-x2.git  2. 安装依赖对于 Ubuntu&#x2F;Debian： 12345678910111213141516171819202122232">
<meta property="og:type" content="article">
<meta property="og:title" content="最佳实践 | 源码编译安装配置 Postgres-XC 集群并用 pg_basebackup 配置 Datanode 热备">
<meta property="og:url" content="http://dbkernel.github.io/2016/03/15/how-to-install-postgres-xc-on-linux/index.html">
<meta property="og:site_name" content="DBKernel">
<meta property="og:description" content="本文首发于 2016-03-15 19:56:52  注意：本篇文章成文时 Postgres-XC 还未改名为 Postgres-X2 。 1. 下载源码1git clone git@github.com:postgres-x2&#x2F;postgres-x2.git  2. 安装依赖对于 Ubuntu&#x2F;Debian： 12345678910111213141516171819202122232">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://dbkernel-1306518848.cos.ap-beijing.myqcloud.com/wechat/my-wechat-official-account.png">
<meta property="article:published_time" content="2016-03-15T11:56:52.000Z">
<meta property="article:modified_time" content="2021-09-22T15:24:33.492Z">
<meta property="article:author" content="DBKernel">
<meta property="article:tag" content="Linux">
<meta property="article:tag" content="PostgreSQL">
<meta property="article:tag" content="Postgres-X2">
<meta property="article:tag" content="Postgres-XC">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://dbkernel-1306518848.cos.ap-beijing.myqcloud.com/wechat/my-wechat-official-account.png">
  <!-- Canonical links -->
  <link rel="canonical" href="http://dbkernel.github.io/2016/03/15/how-to-install-postgres-xc-on-linux/index.html">
  
    <link rel="alternate" href="/atom.xml" title="DBKernel" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  
<link rel="stylesheet" href="../../../../css/style.css">

  
  
  
  
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1.4.0/dist/gitalk.min.css">
  
<meta name="generator" content="Hexo 5.4.0"></head>


<body class="main-center" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://github.com/dbkernel" target="_blank">
          <img class="img-circle img-rotate" src="../../../../images/avatar.png" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">DBKernel</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">资深数据库开发工程师</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Beijing, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
        <li class="menu-item menu-item-home">
          <a href="../../../../.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="../../../../archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="../../../../categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="../../../../tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-repository">
          <a href="../../../../repository">
            
            <i class="icon icon-project"></i>
            
            <span class="menu-title">项目</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-links">
          <a href="../../../../links">
            
            <i class="icon icon-friendship"></i>
            
            <span class="menu-title">友链</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="../../../../about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="../../../../https:/github.com/dbkernel" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="../../../../atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>本站专注于分享关系型数据库及分布式数据库相关技术！如需深入交流，可添加我的微信或关注我的公众号数据库内核：</br><img src="/images/wechat-me.jpeg" width="130" height="130"/> <img src="/images/wechat-gzh.jpeg" width="130" height="130"/></p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="../../../../categories/ClickHouse/">ClickHouse</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/C%E8%AF%AD%E8%A8%80/">C语言</a><span class="category-list-count">8</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/GreenPlum/">GreenPlum</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/Linux/">Linux</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/MySQL/">MySQL</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/PostgreSQL/">PostgreSQL</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/Postgres-X2/">Postgres-X2</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/%E7%BC%96%E8%AF%91%E8%B0%83%E8%AF%95/">编译调试</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/%E9%80%9A%E7%94%A8/">通用</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/APUE/" rel="tag">APUE</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/B-Tree/" rel="tag">B-Tree</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/ClickHouse/" rel="tag">ClickHouse</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/ClickHouse%E5%92%8C%E4%BB%96%E7%9A%84%E6%9C%8B%E5%8F%8B%E4%BB%AC/" rel="tag">ClickHouse和他的朋友们</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Count/" rel="tag">Count</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/C%E8%AF%AD%E8%A8%80/" rel="tag">C语言</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/DAG-Scheduler/" rel="tag">DAG Scheduler</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/GreenPlum/" rel="tag">GreenPlum</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/HEAP%E5%BC%95%E6%93%8E/" rel="tag">HEAP引擎</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/LICENCE/" rel="tag">LICENCE</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/LSM-Tree/" rel="tag">LSM-Tree</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Linux/" rel="tag">Linux</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/MEMORY%E5%BC%95%E6%93%8E/" rel="tag">MEMORY引擎</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Makefile/" rel="tag">Makefile</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Materialized-View/" rel="tag">Materialized View</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/MergeTree/" rel="tag">MergeTree</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/MySQL/" rel="tag">MySQL</a><span class="tag-list-count">8</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Parser/" rel="tag">Parser</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Percona/" rel="tag">Percona</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/PostgreSQL/" rel="tag">PostgreSQL</a><span class="tag-list-count">11</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Postgres-X2/" rel="tag">Postgres-X2</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Postgres-XC/" rel="tag">Postgres-XC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/RadonDB/" rel="tag">RadonDB</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/ReplicatedMergeTree/" rel="tag">ReplicatedMergeTree</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Select/" rel="tag">Select</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/UNIX/" rel="tag">UNIX</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/WAL/" rel="tag">WAL</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Xenon/" rel="tag">Xenon</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Xtrabackup/" rel="tag">Xtrabackup</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/auto-increment/" rel="tag">auto_increment</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/crontab/" rel="tag">crontab</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/daemon/" rel="tag">daemon</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/df/" rel="tag">df</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/du/" rel="tag">du</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/gcc/" rel="tag">gcc</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/gcov/" rel="tag">gcov</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/getopt/" rel="tag">getopt</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/github/" rel="tag">github</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/group-by/" rel="tag">group by</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/lcov/" rel="tag">lcov</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/libpq/" rel="tag">libpq</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/pg-constraint/" rel="tag">pg_constraint</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/pg-depend/" rel="tag">pg_depend</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/pgbench/" rel="tag">pgbench</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/pipeline/" rel="tag">pipeline</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/processor/" rel="tag">processor</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/shell/" rel="tag">shell</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/" rel="tag">主从同步</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E4%BC%98%E5%8C%96%E5%99%A8/" rel="tag">优化器</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D/" rel="tag">内存分配</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/" rel="tag">内存管理</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%9B%9E%E5%BD%92%E6%B5%8B%E8%AF%95/" rel="tag">回归测试</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%AD%97%E8%8A%82%E5%AF%B9%E9%BD%90/" rel="tag">字节对齐</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%AD%97%E8%8A%82%E5%BA%8F/" rel="tag">字节序</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%AD%98%E5%82%A8%E8%AE%A1%E7%AE%97%E5%88%86%E7%A6%BB/" rel="tag">存储计算分离</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%B9%B6%E8%A1%8C%E6%9F%A5%E8%AF%A2/" rel="tag">并行查询</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%BC%80%E6%BA%90%E5%8D%8F%E8%AE%AE/" rel="tag">开源协议</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%BC%80%E6%BA%90%E8%AE%B8%E5%8F%AF%E8%AF%81/" rel="tag">开源许可证</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E6%9C%AC%E5%9C%B0%E4%BA%8B%E5%8A%A1/" rel="tag">本地事务</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90/" rel="tag">源码分析</a><span class="tag-list-count">15</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4/" rel="tag">系统运维</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E7%BC%96%E8%AF%91%E5%99%A8/" rel="tag">编译器</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E7%BD%91%E7%BB%9C%E5%BA%8F/" rel="tag">网络序</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/" rel="tag">网络编程</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E9%97%AE%E9%A2%98%E5%AE%9A%E4%BD%8D/" rel="tag">问题定位</a><span class="tag-list-count">2</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="../../../../tags/APUE/" style="font-size: 13.33px;">APUE</a> <a href="../../../../tags/B-Tree/" style="font-size: 13px;">B-Tree</a> <a href="../../../../tags/ClickHouse/" style="font-size: 13.89px;">ClickHouse</a> <a href="../../../../tags/ClickHouse%E5%92%8C%E4%BB%96%E7%9A%84%E6%9C%8B%E5%8F%8B%E4%BB%AC/" style="font-size: 13.89px;">ClickHouse和他的朋友们</a> <a href="../../../../tags/Count/" style="font-size: 13px;">Count</a> <a href="../../../../tags/C%E8%AF%AD%E8%A8%80/" style="font-size: 13.67px;">C语言</a> <a href="../../../../tags/DAG-Scheduler/" style="font-size: 13px;">DAG Scheduler</a> <a href="../../../../tags/GreenPlum/" style="font-size: 13.22px;">GreenPlum</a> <a href="../../../../tags/HEAP%E5%BC%95%E6%93%8E/" style="font-size: 13px;">HEAP引擎</a> <a href="../../../../tags/LICENCE/" style="font-size: 13px;">LICENCE</a> <a href="../../../../tags/LSM-Tree/" style="font-size: 13px;">LSM-Tree</a> <a href="../../../../tags/Linux/" style="font-size: 13.44px;">Linux</a> <a href="../../../../tags/MEMORY%E5%BC%95%E6%93%8E/" style="font-size: 13px;">MEMORY引擎</a> <a href="../../../../tags/Makefile/" style="font-size: 13px;">Makefile</a> <a href="../../../../tags/Materialized-View/" style="font-size: 13px;">Materialized View</a> <a href="../../../../tags/MergeTree/" style="font-size: 13.11px;">MergeTree</a> <a href="../../../../tags/MySQL/" style="font-size: 13.56px;">MySQL</a> <a href="../../../../tags/Parser/" style="font-size: 13px;">Parser</a> <a href="../../../../tags/Percona/" style="font-size: 13px;">Percona</a> <a href="../../../../tags/PostgreSQL/" style="font-size: 13.78px;">PostgreSQL</a> <a href="../../../../tags/Postgres-X2/" style="font-size: 13px;">Postgres-X2</a> <a href="../../../../tags/Postgres-XC/" style="font-size: 13px;">Postgres-XC</a> <a href="../../../../tags/RadonDB/" style="font-size: 13px;">RadonDB</a> <a href="../../../../tags/ReplicatedMergeTree/" style="font-size: 13px;">ReplicatedMergeTree</a> <a href="../../../../tags/Select/" style="font-size: 13px;">Select</a> <a href="../../../../tags/UNIX/" style="font-size: 13.22px;">UNIX</a> <a href="../../../../tags/WAL/" style="font-size: 13.11px;">WAL</a> <a href="../../../../tags/Xenon/" style="font-size: 13px;">Xenon</a> <a href="../../../../tags/Xtrabackup/" style="font-size: 13px;">Xtrabackup</a> <a href="../../../../tags/auto-increment/" style="font-size: 13px;">auto_increment</a> <a href="../../../../tags/crontab/" style="font-size: 13px;">crontab</a> <a href="../../../../tags/daemon/" style="font-size: 13px;">daemon</a> <a href="../../../../tags/df/" style="font-size: 13px;">df</a> <a href="../../../../tags/du/" style="font-size: 13px;">du</a> <a href="../../../../tags/gcc/" style="font-size: 13px;">gcc</a> <a href="../../../../tags/gcov/" style="font-size: 13px;">gcov</a> <a href="../../../../tags/getopt/" style="font-size: 13px;">getopt</a> <a href="../../../../tags/github/" style="font-size: 13px;">github</a> <a href="../../../../tags/group-by/" style="font-size: 13px;">group by</a> <a href="../../../../tags/lcov/" style="font-size: 13px;">lcov</a> <a href="../../../../tags/libpq/" style="font-size: 13px;">libpq</a> <a href="../../../../tags/pg-constraint/" style="font-size: 13px;">pg_constraint</a> <a href="../../../../tags/pg-depend/" style="font-size: 13px;">pg_depend</a> <a href="../../../../tags/pgbench/" style="font-size: 13px;">pgbench</a> <a href="../../../../tags/pipeline/" style="font-size: 13px;">pipeline</a> <a href="../../../../tags/processor/" style="font-size: 13px;">processor</a> <a href="../../../../tags/shell/" style="font-size: 13px;">shell</a> <a href="../../../../tags/%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/" style="font-size: 13.11px;">主从同步</a> <a href="../../../../tags/%E4%BC%98%E5%8C%96%E5%99%A8/" style="font-size: 13px;">优化器</a> <a href="../../../../tags/%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D/" style="font-size: 13px;">内存分配</a> <a href="../../../../tags/%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/" style="font-size: 13px;">内存管理</a> <a href="../../../../tags/%E5%9B%9E%E5%BD%92%E6%B5%8B%E8%AF%95/" style="font-size: 13px;">回归测试</a> <a href="../../../../tags/%E5%AD%97%E8%8A%82%E5%AF%B9%E9%BD%90/" style="font-size: 13.11px;">字节对齐</a> <a href="../../../../tags/%E5%AD%97%E8%8A%82%E5%BA%8F/" style="font-size: 13.11px;">字节序</a> <a href="../../../../tags/%E5%AD%98%E5%82%A8%E8%AE%A1%E7%AE%97%E5%88%86%E7%A6%BB/" style="font-size: 13px;">存储计算分离</a> <a href="../../../../tags/%E5%B9%B6%E8%A1%8C%E6%9F%A5%E8%AF%A2/" style="font-size: 13px;">并行查询</a> <a href="../../../../tags/%E5%BC%80%E6%BA%90%E5%8D%8F%E8%AE%AE/" style="font-size: 13px;">开源协议</a> <a href="../../../../tags/%E5%BC%80%E6%BA%90%E8%AE%B8%E5%8F%AF%E8%AF%81/" style="font-size: 13px;">开源许可证</a> <a href="../../../../tags/%E6%9C%AC%E5%9C%B0%E4%BA%8B%E5%8A%A1/" style="font-size: 13px;">本地事务</a> <a href="../../../../tags/%E6%B5%8B%E8%AF%95/" style="font-size: 13px;">测试</a> <a href="../../../../tags/%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90/" style="font-size: 14px;">源码分析</a> <a href="../../../../tags/%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4/" style="font-size: 13px;">系统运维</a> <a href="../../../../tags/%E7%BC%96%E8%AF%91%E5%99%A8/" style="font-size: 13px;">编译器</a> <a href="../../../../tags/%E7%BD%91%E7%BB%9C%E5%BA%8F/" style="font-size: 13.11px;">网络序</a> <a href="../../../../tags/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/" style="font-size: 13px;">网络编程</a> <a href="../../../../tags/%E9%97%AE%E9%A2%98%E5%AE%9A%E4%BD%8D/" style="font-size: 13.11px;">问题定位</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2021/08/">八月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2021/01/">一月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/09/">九月 2020</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/08/">八月 2020</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/07/">七月 2020</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/06/">六月 2020</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/05/">五月 2020</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2019/12/">十二月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2019/04/">四月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2018/09/">九月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2016/11/">十一月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2016/04/">四月 2016</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2016/03/">三月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2016/01/">一月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2015/12/">十二月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2015/11/">十一月 2015</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2015/05/">五月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2015/01/">一月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2014/08/">八月 2014</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2014/07/">七月 2014</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2014/03/">三月 2014</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2014/01/">一月 2014</a><span class="archive-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="../../../../categories/%E9%80%9A%E7%94%A8/">通用</a>
              </p>
              <p class="item-title">
                <a href="../../../../2021/08/19/how-to-choose-open-source-licence/" class="title">技术分享 | 如何为你的代码选择一个合适的开源协议？</a>
              </p>
              <p class="item-date">
                <time datetime="2021-08-18T16:37:15.000Z" itemprop="datePublished">2021-08-19</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="../../../../categories/ClickHouse/">ClickHouse</a>
              </p>
              <p class="item-title">
                <a href="../../../../2021/01/26/clickhouse-and-friends-15-groupby/" class="title">源码分析 | ClickHouse和他的朋友们（15）Group By 为什么这么快</a>
              </p>
              <p class="item-date">
                <time datetime="2021-01-26T13:31:12.000Z" itemprop="datePublished">2021-01-26</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="../../../../categories/ClickHouse/">ClickHouse</a>
              </p>
              <p class="item-title">
                <a href="../../../../2020/09/21/clickhouse-and-friends-14-compute-storage/" class="title">源码分析 | ClickHouse和他的朋友们（14）存储计算分离方案与实现</a>
              </p>
              <p class="item-date">
                <time datetime="2020-09-21T14:01:12.000Z" itemprop="datePublished">2020-09-21</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="../../../../categories/ClickHouse/">ClickHouse</a>
              </p>
              <p class="item-title">
                <a href="../../../../2020/09/15/clickhouse-and-friends-13-replicated-merge-tree/" class="title">源码分析 | ClickHouse和他的朋友们（13）ReplicatedMergeTree表引擎及同步机制</a>
              </p>
              <p class="item-date">
                <time datetime="2020-09-15T12:15:14.000Z" itemprop="datePublished">2020-09-15</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="../../../../categories/ClickHouse/">ClickHouse</a>
              </p>
              <p class="item-title">
                <a href="../../../../2020/09/03/clickhouse-and-friends-12-materialized-view/" class="title">源码分析 | ClickHouse和他的朋友们（12）神奇的物化视图(Materialized View)与原理</a>
              </p>
              <p class="item-date">
                <time datetime="2020-09-03T13:22:14.000Z" itemprop="datePublished">2020-09-03</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-%E4%B8%8B%E8%BD%BD%E6%BA%90%E7%A0%81"><span class="toc-number">1.</span> <span class="toc-text">1. 下载源码</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96"><span class="toc-number">2.</span> <span class="toc-text">2. 安装依赖</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85"><span class="toc-number">3.</span> <span class="toc-text">3. 编译安装</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#4-%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%81%E5%90%AF%E5%8A%A8"><span class="toc-number">4.</span> <span class="toc-text">4. 初始化、启动</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#4-1-%E5%88%9D%E5%A7%8B%E5%8C%96-GTM"><span class="toc-number">4.1.</span> <span class="toc-text">4.1. 初始化 GTM</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-2-%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E6%8D%AE%E5%BA%93%E8%8A%82%E7%82%B9"><span class="toc-number">4.2.</span> <span class="toc-text">4.2. 初始化数据库节点</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-3-%E7%BC%96%E8%BE%91%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">4.3.</span> <span class="toc-text">4.3. 编辑配置文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-4-%E5%90%AF%E5%8A%A8%E6%9C%8D%E5%8A%A1"><span class="toc-number">4.4.</span> <span class="toc-text">4.4. 启动服务</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#5-%E9%85%8D%E7%BD%AE%E9%9B%86%E7%BE%A4%E8%8A%82%E7%82%B9"><span class="toc-number">5.</span> <span class="toc-text">5. 配置集群节点</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#6-%E5%B8%B8%E8%A7%81%E6%93%8D%E4%BD%9C"><span class="toc-number">6.</span> <span class="toc-text">6. 常见操作</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#6-1-%E5%81%9C%E6%AD%A2%E9%9B%86%E7%BE%A4"><span class="toc-number">6.1.</span> <span class="toc-text">6.1. 停止集群</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-2-%E5%90%AF%E5%8A%A8%E9%9B%86%E7%BE%A4"><span class="toc-number">6.2.</span> <span class="toc-text">6.2. 启动集群</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-3-%E6%B8%85%E7%90%86%E6%95%B0%E6%8D%AE"><span class="toc-number">6.3.</span> <span class="toc-text">6.3. 清理数据</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#7-%E9%85%8D%E7%BD%AE-Datanode-%E7%83%AD%E5%A4%87"><span class="toc-number">7.</span> <span class="toc-text">7. 配置 Datanode 热备</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#7-1-%E4%BF%AE%E6%94%B9%E6%89%80%E6%9C%89-CO-%E5%92%8C-DN-%E7%9A%84-pg-hba-conf"><span class="toc-number">7.1.</span> <span class="toc-text">7.1. 修改所有 CO 和 DN 的 pg_hba.conf</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-2-%E4%BF%AE%E6%94%B9%E6%89%80%E6%9C%89-CO-%E5%92%8C-DN-%E7%9A%84-postgresql-conf"><span class="toc-number">7.2.</span> <span class="toc-text">7.2. 修改所有 CO 和 DN 的 postgresql.conf</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-3-%E5%88%9B%E5%BB%BA%E5%A4%87-DN"><span class="toc-number">7.3.</span> <span class="toc-text">7.3. 创建备 DN</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-4-%E5%9C%A8%E6%89%80%E6%9C%89%E5%A4%87-DN-%E6%96%B0%E5%BB%BA-recovery-conf"><span class="toc-number">7.4.</span> <span class="toc-text">7.4. 在所有备 DN 新建 recovery.conf</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-5-%E5%9C%A8%E6%89%80%E6%9C%89%E4%B8%BB-DN-%E6%96%B0%E5%BB%BA-synchronous-standby-names-conf"><span class="toc-number">7.5.</span> <span class="toc-text">7.5. 在所有主 DN 新建 synchronous_standby_names.conf</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-6-%E5%9C%A8%E6%89%80%E6%9C%89-CO-%E6%B7%BB%E5%8A%A0%E5%A4%87-DN-%E8%8A%82%E7%82%B9"><span class="toc-number">7.6.</span> <span class="toc-text">7.6. 在所有 CO 添加备 DN 节点</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-7-%E5%90%AF%E5%8A%A8%E6%89%80%E6%9C%89%E5%A4%87-DN-%E6%9C%8D%E5%8A%A1"><span class="toc-number">7.7.</span> <span class="toc-text">7.7. 启动所有备 DN 服务</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#8-Q-amp-A"><span class="toc-number">8.</span> <span class="toc-text">8. Q&amp;A</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#8-1-%E5%A6%82%E4%BD%95%E6%8F%90%E5%8D%87%E5%A4%87-DN-%E4%B8%BA%E4%B8%BB-DN"><span class="toc-number">8.1.</span> <span class="toc-text">8.1. 如何提升备 DN 为主 DN</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8-2-%E5%BD%93%E5%A4%87-DN-%E6%8C%82%E6%8E%89%E6%97%B6%EF%BC%8C%E5%A6%82%E4%BD%95%E5%85%B3%E9%97%AD%E4%B8%BB%E5%A4%87-DN-%E4%B9%8B%E9%97%B4%E7%9A%84%E6%95%B0%E6%8D%AE%E5%90%8C%E6%AD%A5"><span class="toc-number">8.2.</span> <span class="toc-text">8.2. 当备 DN 挂掉时，如何关闭主备 DN 之间的数据同步</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%A1%A5%E5%85%85"><span class="toc-number">8.3.</span> <span class="toc-text">补充</span></a></li></ol></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-how-to-install-postgres-xc-on-linux" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      最佳实践 | 源码编译安装配置 Postgres-XC 集群并用 pg_basebackup 配置 Datanode 热备
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="" class="article-date">
	  <time datetime="2016-03-15T11:56:52.000Z" itemprop="datePublished">2016-03-15</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="../../../../categories/Postgres-X2/">Postgres-X2</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link-link" href="../../../../tags/Linux/" rel="tag">Linux</a>, <a class="article-tag-link-link" href="../../../../tags/PostgreSQL/" rel="tag">PostgreSQL</a>, <a class="article-tag-link-link" href="../../../../tags/Postgres-X2/" rel="tag">Postgres-X2</a>, <a class="article-tag-link-link" href="../../../../tags/Postgres-XC/" rel="tag">Postgres-XC</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


        <span class="post-comment"><i class="icon icon-comment"></i> <a href="#comments" class="article-comment-link">评论</a></span>
        
	
		<span class="post-wordcount hidden-xs" itemprop="wordCount">字数统计: 2.3k(字)</span>
	
	
		<span class="post-readcount hidden-xs" itemprop="timeRequired">阅读时长: 12(分)</span>
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <span id="more"></span>



<blockquote>
<p><strong>本文首发于 2016-03-15 19:56:52</strong></p>
</blockquote>
<p>注意：本篇文章成文时 Postgres-XC 还未改名为 Postgres-X2 。</p>
<h1 id="1-下载源码"><a href="#1-下载源码" class="headerlink" title="1. 下载源码"></a>1. 下载源码</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> git@github.com:postgres-x2/postgres-x2.git</span><br></pre></td></tr></table></figure>

<h1 id="2-安装依赖"><a href="#2-安装依赖" class="headerlink" title="2. 安装依赖"></a>2. 安装依赖</h1><p><strong>对于 Ubuntu/Debian：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">apt-get install -y git-core</span><br><span class="line">apt-get install -y gcc g++</span><br><span class="line">apt-get install -y ccache</span><br><span class="line">apt-get install -y libreadline-dev</span><br><span class="line">apt-get install -y bison flex</span><br><span class="line">apt-get install -y zlib1g-dev</span><br><span class="line">apt-get install -y openssl libssl-dev</span><br><span class="line">apt-get install -y libpam-dev</span><br><span class="line">apt-get install -y libcurl4-dev</span><br><span class="line">apt-get install -y libbz2-dev</span><br><span class="line">apt-get install -y python-dev</span><br><span class="line">apt-get install -y ssh</span><br><span class="line"></span><br><span class="line">apt-get install -y libcurl4-dev</span><br><span class="line">Package libcurl4-dev is a virtual package provided by:</span><br><span class="line">libcurl4-openssl-dev 7.38.0-4+deb8u2</span><br><span class="line">libcurl4-nss-dev 7.38.0-4+deb8u2</span><br><span class="line">libcurl4-gnutls-dev 7.38.0-4+deb8u2</span><br><span class="line"></span><br><span class="line">apt-get install -y python-pip</span><br><span class="line"></span><br><span class="line">pip install lockfile</span><br><span class="line">pip install paramiko</span><br><span class="line">pip install setuptools</span><br><span class="line">pip install epydoc</span><br><span class="line">pip install psi</span><br><span class="line"></span><br><span class="line">Note: debian8 required pip install --pre psi</span><br></pre></td></tr></table></figure>

<p><strong>对于 CentOS：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">yum install –y git.x86_64</span><br><span class="line">yum install –y gcc.x86_64 gcc-c++.x86_64</span><br><span class="line">yum install –y ccache.x86_64</span><br><span class="line">yum install readline.x86_64 readline-devel.x86_64</span><br><span class="line">yum install bison.x86_64 bison-devel.x86_64</span><br><span class="line">yum install flex.x86_64 flex-devel.x86_64</span><br><span class="line">yum install zlib.x86_64 zlib-devel.x86_64</span><br><span class="line">yum install -y openssl.x86_64 openssl-devel.x86_64</span><br><span class="line">yum install -y pam.x86_64 pam-devel.x86_64</span><br><span class="line">yum install –y libcurl.x86_64 libcurl-devel.x86_64</span><br><span class="line">yum install bzip2-libs.x86_64 bzip2.x86_64 bzip2-devel.x86_64</span><br><span class="line">yum install libssh2.x86_64 libssh2-devel.x86_64</span><br><span class="line">yum install python-devel.x86_64</span><br><span class="line">yum install -y python-pip.noarch</span><br><span class="line"></span><br><span class="line"><span class="comment"># 接着执行：</span></span><br><span class="line">pip install lockfile</span><br><span class="line">pip install paramiko</span><br><span class="line">pip install setuptools</span><br><span class="line">pip install epydoc</span><br><span class="line">pip install psi</span><br><span class="line"><span class="comment"># 或者执行：</span></span><br><span class="line">yum install python-lockfile.noarch</span><br><span class="line">yum install python-PSI.x86_64</span><br><span class="line">yum install python-paramiko.noarch</span><br><span class="line">yum install python-setuptools.noarch</span><br><span class="line">yum install epydoc.noarch</span><br></pre></td></tr></table></figure>

<h1 id="3-编译安装"><a href="#3-编译安装" class="headerlink" title="3. 编译安装"></a>3. 编译安装</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">cd</span> postgres-x2</span><br><span class="line">$ ./configure --prefix=/home/wslu/pgsql --enable-debug <span class="comment">#其中--prefix指定编绎完成后将要安装的路径，必须使用全路径，wslu为使用者。</span></span><br><span class="line">$ make <span class="comment">#执行编绎</span></span><br><span class="line">$ make install <span class="comment">#执行安装</span></span><br></pre></td></tr></table></figure>

<h1 id="4-初始化、启动"><a href="#4-初始化、启动" class="headerlink" title="4. 初始化、启动"></a>4. 初始化、启动</h1><h2 id="4-1-初始化-GTM"><a href="#4-1-初始化-GTM" class="headerlink" title="4.1. 初始化 GTM"></a>4.1. 初始化 GTM</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">cd</span> /home/wslu/pgsql</span><br><span class="line"></span><br><span class="line"><span class="comment">#设置PTAH变量</span></span><br><span class="line">$ <span class="built_in">export</span> PATH=/home/user/pgsql/bin:<span class="variable">$PATH</span></span><br><span class="line"><span class="comment">#使用初始化gtm命令initgtm</span></span><br><span class="line">$ ./bin/initgtm -Z gtm -D data/gtm/</span><br></pre></td></tr></table></figure>

<h2 id="4-2-初始化数据库节点"><a href="#4-2-初始化数据库节点" class="headerlink" title="4.2. 初始化数据库节点"></a>4.2. 初始化数据库节点</h2><p>初始化所有数据库节点（CO、DN）：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#使用初始化db命令initdb</span></span><br><span class="line">$ ./bin/initdb -U wslu -A trust --locale=C -D data/co1   <span class="comment"># -U 使用者 -D 数据目录/节点</span></span><br><span class="line">$ ./bin/initdb -U wslu -A trust --locale=C -D data/co2</span><br><span class="line">$ ./bin/initdb -U wslu -A trust --locale=C -D data/dn1</span><br><span class="line">$ ./bin/initdb -U wslu -A trust --locale=C -D data/dn2</span><br><span class="line">$ ./bin/initdb -U wslu -A trust --locale=C -D data/dn3</span><br></pre></td></tr></table></figure>

<h2 id="4-3-编辑配置文件"><a href="#4-3-编辑配置文件" class="headerlink" title="4.3. 编辑配置文件"></a>4.3. 编辑配置文件</h2><p>编辑 data/co1/postgresql.conf：</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 默认值</span></span><br><span class="line"><span class="attr">gtm_port</span> = <span class="number">6666</span></span><br><span class="line"><span class="comment"># pgxc_node_name 不能重复</span></span><br><span class="line"><span class="attr">pgxc_node_name</span> = co1</span><br></pre></td></tr></table></figure>

<p>编辑 data/co2/postgresql.conf：</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">gtm_port</span> = <span class="number">6666</span></span><br><span class="line"><span class="attr">pgxc_node_name</span> = co2</span><br></pre></td></tr></table></figure>

<p>编辑 data/dn1/postgresql.conf：</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">gtm_port</span> = <span class="number">6666</span></span><br><span class="line"><span class="attr">pgxc_node_name</span> = dn1</span><br></pre></td></tr></table></figure>

<p>编辑 data/dn2/postgresql.conf：</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">gtm_port</span> = <span class="number">6666</span></span><br><span class="line"><span class="attr">pgxc_node_name</span> = dn2</span><br></pre></td></tr></table></figure>

<p>编辑 data/dn2/postgresql.conf：</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">gtm_port</span> = <span class="number">6666</span></span><br><span class="line"><span class="attr">pgxc_node_name</span> = dn3</span><br></pre></td></tr></table></figure>

<h2 id="4-4-启动服务"><a href="#4-4-启动服务" class="headerlink" title="4.4. 启动服务"></a>4.4. 启动服务</h2><p>依次启动 gtm、datanode、coordinator：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ./bin/gtm_ctl start -S gtm -D data/gtm -l data/gtm/gtm.log  //启动gtm（由于切换为相对路径后找不到对应的文件夹，所以创建日志会失败）</span></span><br><span class="line">$ ./bin/gtm_ctl start -Z gtm -D data/gtm -l gtm.log  //启动gtm</span><br><span class="line"><span class="comment"># vim data/gtm/gtm.log # 使用日志查看gtm是否启动</span></span><br><span class="line"></span><br><span class="line">$ ./bin/pg_ctl start -Z datanode -D data/dn1 -l data/dn1/postgresql.log  -o <span class="string">&quot;-p 24071&quot;</span>   //启动datanode dn1， DN1_PORT=24071   根据需要自由设置</span><br><span class="line"><span class="comment"># vim data/dn1/postgresql.log # 同样使用日志查看是否启动</span></span><br><span class="line"></span><br><span class="line">$ ./bin/pg_ctl start -Z datanode -D data/dn2 -l data/dn2/postgresql.log  -o <span class="string">&quot;-p 24072&quot;</span>  //启动 dn2， DN2_PORT=24072</span><br><span class="line">$ ./bin/pg_ctl start -Z datanode -D data/dn3 -l data/dn3/postgresql.log  -o <span class="string">&quot;-p 24073&quot;</span>  //启动 dn3， DN3_PORT=24073</span><br><span class="line"></span><br><span class="line">$ ./bin/pg_ctl start -Z coordinator -D data/co1 -l data/co1/postgresql.log  -o <span class="string">&quot;-p 24076&quot;</span>   //启动 coordinator co1， CO1_PORT=24076</span><br><span class="line">$ ./bin/pg_ctl start -Z coordinator -D data/co2 -l data/co2/postgresql.log  -o <span class="string">&quot;-p 24077&quot;</span>   //启动 co2， CO2_PORT= 24077</span><br></pre></td></tr></table></figure>

<h1 id="5-配置集群节点"><a href="#5-配置集群节点" class="headerlink" title="5. 配置集群节点"></a>5. 配置集群节点</h1><p>指定动态库位置：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">export</span> LD_LIBRARY_PATH=/home/wslu/pgsql/lib:<span class="variable">$LD_LIBRARY_PATH</span></span><br></pre></td></tr></table></figure>

<p>配置集群节点：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"># 进入co1创建节点，co1_port<span class="operator">=</span><span class="number">24076</span></span><br><span class="line">$ .<span class="operator">/</span>bin<span class="operator">/</span>psql <span class="operator">-</span>p <span class="number">24076</span> postgres postgres</span><br><span class="line"></span><br><span class="line"> <span class="keyword">CREATE</span> NODE dn1 <span class="keyword">WITH</span> (HOST <span class="operator">=</span> <span class="string">&#x27;localhost&#x27;</span>, type <span class="operator">=</span> <span class="string">&#x27;datanode&#x27;</span>, PORT <span class="operator">=</span> <span class="number">24071</span>, id <span class="operator">=</span> <span class="number">1</span>, content <span class="operator">=</span> <span class="number">1</span>); <span class="operator">/</span><span class="operator">/</span>在协调器上注册节点，各端口号与上面一致</span><br><span class="line"> <span class="keyword">CREATE</span> NODE dn2 <span class="keyword">WITH</span> (HOST <span class="operator">=</span> <span class="string">&#x27;localhost&#x27;</span>, type <span class="operator">=</span> <span class="string">&#x27;datanode&#x27;</span>, PORT <span class="operator">=</span> <span class="number">24072</span>, id <span class="operator">=</span> <span class="number">2</span>, content <span class="operator">=</span> <span class="number">2</span>);</span><br><span class="line"> <span class="keyword">CREATE</span> NODE dn3 <span class="keyword">WITH</span> (HOST <span class="operator">=</span> <span class="string">&#x27;localhost&#x27;</span>, type <span class="operator">=</span> <span class="string">&#x27;datanode&#x27;</span>, PORT <span class="operator">=</span> <span class="number">24073</span>, id <span class="operator">=</span> <span class="number">3</span>, content <span class="operator">=</span> <span class="number">3</span>);</span><br><span class="line"> <span class="keyword">CREATE</span> NODE co1 <span class="keyword">WITH</span> (HOST <span class="operator">=</span> <span class="string">&#x27;localhost&#x27;</span>, type <span class="operator">=</span> <span class="string">&#x27;coordinator&#x27;</span>, PORT <span class="operator">=</span> <span class="number">24076</span>, id <span class="operator">=</span> <span class="number">4</span>, content <span class="operator">=</span> <span class="number">4</span>);</span><br><span class="line"> <span class="keyword">CREATE</span> NODE co2 <span class="keyword">WITH</span> (HOST <span class="operator">=</span> <span class="string">&#x27;localhost&#x27;</span>, type <span class="operator">=</span> <span class="string">&#x27;coordinator&#x27;</span>, PORT <span class="operator">=</span> <span class="number">24077</span>, id <span class="operator">=</span> <span class="number">5</span>, content <span class="operator">=</span> <span class="number">5</span>);</span><br><span class="line"> <span class="keyword">SELECT</span> pgxc_pool_reload();</span><br></pre></td></tr></table></figure>

<p>至此，集群配置完成。</p>
<h1 id="6-常见操作"><a href="#6-常见操作" class="headerlink" title="6. 常见操作"></a>6. 常见操作</h1><h2 id="6-1-停止集群"><a href="#6-1-停止集群" class="headerlink" title="6.1. 停止集群"></a>6.1. 停止集群</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ ./bin/pg_ctl stop -D data/co1 -m immediate</span><br><span class="line">$ ./bin/pg_ctl stop -D data/co2 -m immediate</span><br><span class="line">$ ./bin/pg_ctl stop -D data/dn1 -m immediate</span><br><span class="line">$ ./bin/pg_ctl stop -D data/dn2 -m immediate</span><br><span class="line">$ ./bin/pg_ctl stop -D data/dn3 -m immediate</span><br><span class="line">$ ./bin/gtm_ctl stop -Z gtm -D data/gtm</span><br><span class="line">$ rm -f data/gtm/register.node</span><br></pre></td></tr></table></figure>

<h2 id="6-2-启动集群"><a href="#6-2-启动集群" class="headerlink" title="6.2. 启动集群"></a>6.2. 启动集群</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">$ ./bin/gtm_ctl start -Z gtm -D data/gtm -p ./bin -l data/gtm/gtm.log</span><br><span class="line">$ ./bin/pg_ctl start -l data/dn1/postgresql.log -Z datanode -D data/dn1 -o <span class="string">&quot;-p 24071&quot;</span></span><br><span class="line">$ ./bin/pg_ctl start -l data/dn2/postgresql.log -Z datanode -D data/dn2 -o <span class="string">&quot;-p 24072&quot;</span></span><br><span class="line">$ ./bin/pg_ctl start -l data/dn3/postgresql.log -Z datanode -D data/dn3 -o <span class="string">&quot;-p 24073&quot;</span></span><br><span class="line">$ ./bin/pg_ctl start -l data/co1/postgresql.log -Z coordinator -D data/co1 -o <span class="string">&quot;-p 24076&quot;</span></span><br><span class="line">$ ./bin/pg_ctl start -l data/co2/postgresql.log -Z coordinator -D data/co2 -o <span class="string">&quot;-p 24077&quot;</span></span><br></pre></td></tr></table></figure>

<h2 id="6-3-清理数据"><a href="#6-3-清理数据" class="headerlink" title="6.3. 清理数据"></a>6.3. 清理数据</h2><p>如需清除数据，请先停止服务器集群，然后清除数据存储目录:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$ ./bin/pg_ctl stop -D data/co1 -m immediate</span><br><span class="line">$ ./bin/pg_ctl stop -D data/co2 -m immediate</span><br><span class="line">$ ./bin/pg_ctl stop -D data/dn1 -m immediate</span><br><span class="line">$ ./bin/pg_ctl stop -D data/dn2 -m immediate</span><br><span class="line">$ ./bin/pg_ctl stop -D data/dn3 -m immediate</span><br><span class="line">$ ./bin/gtm_ctl stop -Z gtm -D data/gtm</span><br><span class="line">$ rm -f data/gtm/register.node</span><br><span class="line">$ rm -rf data</span><br></pre></td></tr></table></figure>

<h1 id="7-配置-Datanode-热备"><a href="#7-配置-Datanode-热备" class="headerlink" title="7. 配置 Datanode 热备"></a>7. 配置 Datanode 热备</h1><h2 id="7-1-修改所有-CO-和-DN-的-pg-hba-conf"><a href="#7-1-修改所有-CO-和-DN-的-pg-hba-conf" class="headerlink" title="7.1. 修改所有 CO 和 DN 的 pg_hba.conf"></a>7.1. 修改所有 CO 和 DN 的 pg_hba.conf</h2><p>将下面两行的注释去掉：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">$ vi data/co1/pg_hba.conf</span><br><span class="line">host    replication     wslu        127.0.0.1/32            trust</span><br><span class="line">host    replication     wslu        ::1/128                 trust</span><br><span class="line"></span><br><span class="line">$ vi data/co2/pg_hba.conf</span><br><span class="line">host    replication     wslu        127.0.0.1/32            trust</span><br><span class="line">host    replication     wslu        ::1/128                 trust</span><br><span class="line"></span><br><span class="line">$ vi data/dn1/pg_hba.conf</span><br><span class="line">host    replication     wslu        127.0.0.1/32            trust</span><br><span class="line">host    replication     wslu        ::1/128                 trust</span><br><span class="line"></span><br><span class="line">$ vi data/dn2/pg_hba.conf</span><br><span class="line">host    replication     wslu        127.0.0.1/32            trust</span><br><span class="line">host    replication     wslu        ::1/128                 trust</span><br><span class="line"></span><br><span class="line">$ vi data/dn3/pg_hba.conf</span><br><span class="line">host    replication     wslu        127.0.0.1/32            trust</span><br><span class="line">host    replication     wslu        ::1/128                 trust</span><br></pre></td></tr></table></figure>

<p>此处为了测试方便，将校验方式设为 trust；实际生产中要改为 md5，即根据账户密码验证。</p>
<h2 id="7-2-修改所有-CO-和-DN-的-postgresql-conf"><a href="#7-2-修改所有-CO-和-DN-的-postgresql-conf" class="headerlink" title="7.2. 修改所有 CO 和 DN 的 postgresql.conf"></a>7.2. 修改所有 CO 和 DN 的 postgresql.conf</h2><p>添加以下内容：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">$ vi data/co1/postgresql.conf</span><br><span class="line">listen_addresses = <span class="string">&#x27;*&#x27;</span></span><br><span class="line">log_line_prefix = <span class="string">&#x27;%t:%r:%u@%d:[%p]: &#x27;</span></span><br><span class="line"><span class="comment">#logging_collector = on</span></span><br><span class="line">port = 24076</span><br><span class="line">wal_level = archive</span><br><span class="line"></span><br><span class="line">$ vi data/co2/postgresql.conf</span><br><span class="line">listen_addresses = <span class="string">&#x27;*&#x27;</span></span><br><span class="line">log_line_prefix = <span class="string">&#x27;%t:%r:%u@%d:[%p]: &#x27;</span></span><br><span class="line"><span class="comment">#logging_collector = on</span></span><br><span class="line">port = 24077</span><br><span class="line">wal_level = archive</span><br><span class="line"></span><br><span class="line">$ vi data/dn1/postgresql.conf</span><br><span class="line">hot_standby = on</span><br><span class="line"><span class="comment">#logging_collector = on</span></span><br><span class="line">listen_addresses = <span class="string">&#x27;*&#x27;</span></span><br><span class="line">log_line_prefix = <span class="string">&#x27;%t:%r:%u@%d:[%p]: &#x27;</span></span><br><span class="line">wal_keep_segments = 10</span><br><span class="line">wal_level = hot_standby</span><br><span class="line">max_wal_senders = 5</span><br><span class="line">include_if_exists = <span class="string">&#x27;synchronous_standby_names.conf&#x27;</span></span><br><span class="line">port = 24071</span><br><span class="line"></span><br><span class="line">$ vi data/dn2/postgresql.conf</span><br><span class="line">hot_standby = on</span><br><span class="line"><span class="comment">#logging_collector = on</span></span><br><span class="line">listen_addresses = <span class="string">&#x27;*&#x27;</span></span><br><span class="line">log_line_prefix = <span class="string">&#x27;%t:%r:%u@%d:[%p]: &#x27;</span></span><br><span class="line">wal_keep_segments = 10</span><br><span class="line">wal_level = hot_standby</span><br><span class="line">max_wal_senders = 5</span><br><span class="line">include_if_exists = <span class="string">&#x27;synchronous_standby_names.conf&#x27;</span></span><br><span class="line">port = 24072</span><br><span class="line"></span><br><span class="line">$ vi data/dn3/postgresql.conf</span><br><span class="line">hot_standby = on</span><br><span class="line"><span class="comment">#logging_collector = on</span></span><br><span class="line">listen_addresses = <span class="string">&#x27;*&#x27;</span></span><br><span class="line">log_line_prefix = <span class="string">&#x27;%t:%r:%u@%d:[%p]: &#x27;</span></span><br><span class="line">wal_keep_segments = 10</span><br><span class="line">wal_level = hot_standby</span><br><span class="line">max_wal_senders = 5</span><br><span class="line">include_if_exists = <span class="string">&#x27;synchronous_standby_names.conf&#x27;</span></span><br><span class="line">port = 24073</span><br></pre></td></tr></table></figure>

<h2 id="7-3-创建备-DN"><a href="#7-3-创建备-DN" class="headerlink" title="7.3. 创建备 DN"></a>7.3. 创建备 DN</h2><p>在数据库集群开启的前提下执行下列指令，以创建备 Datanode 目录：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ pg_basebackup -D data/dn1s -Fp -Xs -v -P -h localhost -p 24071 -U wslu</span><br><span class="line">$ pg_basebackup -D data/dn2s -Fp -Xs -v -P -h localhost -p 24072 -U wslu</span><br><span class="line">$ pg_basebackup -D data/dn3s -Fp -Xs -v -P -h localhost -p 24073 -U wslu</span><br></pre></td></tr></table></figure>

<h2 id="7-4-在所有备-DN-新建-recovery-conf"><a href="#7-4-在所有备-DN-新建-recovery-conf" class="headerlink" title="7.4. 在所有备 DN 新建 recovery.conf"></a>7.4. 在所有备 DN 新建 recovery.conf</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">$ vi dn1s/recovery.conf</span><br><span class="line">standby_mode = <span class="string">&#x27;on&#x27;</span></span><br><span class="line">primary_conninfo = <span class="string">&#x27;user=wslu host=localhost port=24071 sslmode=disable sslcompression=1&#x27;</span></span><br><span class="line"></span><br><span class="line">$ vi dn2s/recovery.conf</span><br><span class="line">standby_mode = <span class="string">&#x27;on&#x27;</span></span><br><span class="line">primary_conninfo = <span class="string">&#x27;user=wslu host=localhost port=24072 sslmode=disable sslcompression=1&#x27;</span></span><br><span class="line"></span><br><span class="line">$ vi dn3s/recovery.conf</span><br><span class="line">standby_mode = <span class="string">&#x27;on&#x27;</span></span><br><span class="line">primary_conninfo = <span class="string">&#x27;user=wslu host=localhost port=24073 sslmode=disable sslcompression=1&#x27;</span></span><br></pre></td></tr></table></figure>

<h2 id="7-5-在所有主-DN-新建-synchronous-standby-names-conf"><a href="#7-5-在所有主-DN-新建-synchronous-standby-names-conf" class="headerlink" title="7.5. 在所有主 DN 新建 synchronous_standby_names.conf"></a>7.5. 在所有主 DN 新建 synchronous_standby_names.conf</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">vi data/dn1/synchronous_standby_names.conf</span><br><span class="line">synchronous_standby_names=<span class="string">&#x27;*&#x27;</span></span><br></pre></td></tr></table></figure>

<h2 id="7-6-在所有-CO-添加备-DN-节点"><a href="#7-6-在所有-CO-添加备-DN-节点" class="headerlink" title="7.6. 在所有 CO 添加备 DN 节点"></a>7.6. 在所有 CO 添加备 DN 节点</h2><p>这里以 co1 为例，co2 也要执行同样操作（ 对于支持热备的其他 pg 商用数据库，类型不是 datanode 而是 standby）：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ .<span class="operator">/</span>bin<span class="operator">/</span>psql <span class="operator">-</span>p <span class="number">24076</span> postgres postgres    <span class="operator">/</span><span class="operator">/</span>进入co1创建节点，co1_port<span class="operator">=</span><span class="number">24076</span></span><br><span class="line"> <span class="keyword">CREATE</span> NODE dn1s <span class="keyword">WITH</span> (HOST <span class="operator">=</span> <span class="string">&#x27;localhost&#x27;</span>, type <span class="operator">=</span> <span class="string">&#x27;datanode&#x27;</span>, PORT <span class="operator">=</span> <span class="number">34071</span>, id <span class="operator">=</span> <span class="number">6</span>, content <span class="operator">=</span> <span class="number">1</span>); <span class="operator">/</span><span class="operator">/</span>在协调器上注册节点，各端口号与上面一致</span><br><span class="line"> <span class="keyword">CREATE</span> NODE dn2s <span class="keyword">WITH</span> (HOST <span class="operator">=</span> <span class="string">&#x27;localhost&#x27;</span>, type <span class="operator">=</span> <span class="string">&#x27;datanode&#x27;</span>, PORT <span class="operator">=</span> <span class="number">34072</span>, id <span class="operator">=</span> <span class="number">7</span>, content <span class="operator">=</span> <span class="number">2</span>);</span><br><span class="line"> <span class="keyword">CREATE</span> NODE dn3s <span class="keyword">WITH</span> (HOST <span class="operator">=</span> <span class="string">&#x27;localhost&#x27;</span>, type <span class="operator">=</span> <span class="string">&#x27;datanode&#x27;</span>, PORT <span class="operator">=</span> <span class="number">34073</span>, id <span class="operator">=</span> <span class="number">8</span>, content <span class="operator">=</span> <span class="number">3</span>);</span><br></pre></td></tr></table></figure>

<h2 id="7-7-启动所有备-DN-服务"><a href="#7-7-启动所有备-DN-服务" class="headerlink" title="7.7. 启动所有备 DN 服务"></a>7.7. 启动所有备 DN 服务</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">./bin/pg_ctl start -D data/dn1s -l data/dn1s/postgresql.log  -o <span class="string">&quot;-p 34071&quot;</span></span><br><span class="line">./bin/pg_ctl start -D data/dn2s -l data/dn2s/postgresql.log  -o <span class="string">&quot;-p 34072&quot;</span></span><br><span class="line">./bin/pg_ctl start -D data/dn3s -l data/dn3s/postgresql.log  -o <span class="string">&quot;-p 34073&quot;</span></span><br></pre></td></tr></table></figure>

<p>相应的，停止所有备 DN 节点服务的指令为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">./bin/pg_ctl stop -D data/dn1s -m immediate</span><br><span class="line">./bin/pg_ctl stop -D data/dn2s -m immediate</span><br><span class="line">./bin/pg_ctl stop -D data/dn3s -m immediate</span><br></pre></td></tr></table></figure>

<h1 id="8-Q-amp-A"><a href="#8-Q-amp-A" class="headerlink" title="8. Q&amp;A"></a>8. Q&amp;A</h1><h2 id="8-1-如何提升备-DN-为主-DN"><a href="#8-1-如何提升备-DN-为主-DN" class="headerlink" title="8.1. 如何提升备 DN 为主 DN"></a>8.1. 如何提升备 DN 为主 DN</h2><p>我并未实现成功，但参照其他 PostgreSQL 的分布式数据库，步骤如下：</p>
<ol>
<li>杀掉主 DN 进程，在备 DN 的目录下创建一个触发文件（例如：promote）文件。</li>
<li>通过 <code>kill -SIGUSR1 备DN进程号</code> 指令给备 DN 的 postmaster 进程发送一个 SIGUSR1 信号。</li>
<li>在主 CO 执行类似 <code>alter node dn1s with(promote);</code> 的指令。</li>
<li>退出 psql，再重新连入 psql。</li>
<li>此时，备 DN 就作为主 DN 运行了，可执行 DDL、DML 等所有操作。</li>
</ol>
<h2 id="8-2-当备-DN-挂掉时，如何关闭主备-DN-之间的数据同步"><a href="#8-2-当备-DN-挂掉时，如何关闭主备-DN-之间的数据同步" class="headerlink" title="8.2. 当备 DN 挂掉时，如何关闭主备 DN 之间的数据同步"></a>8.2. 当备 DN 挂掉时，如何关闭主备 DN 之间的数据同步</h2><p>也就是关闭 walsender 和 walreciever。</p>
<p>这就涉及到源码级别了，一般做两步：</p>
<ol>
<li>将主 DN 状态改为 <code>OutSync</code>（别的数据库的做法）。</li>
<li>在代码中将 <code>SyncRepStandbyNames</code> 设为 <code>&quot;&quot;</code>。</li>
</ol>
<h2 id="补充"><a href="#补充" class="headerlink" title="补充"></a>补充</h2><p>本教程关于配置备 DN 的描述只能对各个 DN 的数据做备份，并未成功实现某个 DN 挂掉了自动切换到备 DN。</p>
<p>另外，我并未在 Postgres-XC（现在 github 改名为了 Postgres-X2）源码的回归测试中看到如何在 pgxc_nodes 系统表创建备 DN 节点。</p>
<p>不过，GreenPlum（以 PostgreSQL 为基础开发的分布式数据库）有此功能，可做参考。</p>
<hr>
<p>欢迎关注我的微信公众号【数据库内核】：分享主流开源数据库和存储引擎相关技术。</p>
<img src="https://dbkernel-1306518848.cos.ap-beijing.myqcloud.com/wechat/my-wechat-official-account.png" width="400" height="400" alt="欢迎关注公众号数据库内核" align="center"/>


<table>
<thead>
<tr>
<th>标题</th>
<th>网址</th>
</tr>
</thead>
<tbody><tr>
<td>GitHub</td>
<td><a href="https://dbkernel.github.io/">https://dbkernel.github.io</a></td>
</tr>
<tr>
<td>知乎</td>
<td><a target="_blank" rel="noopener" href="https://www.zhihu.com/people/dbkernel/posts">https://www.zhihu.com/people/dbkernel/posts</a></td>
</tr>
<tr>
<td>思否（SegmentFault）</td>
<td><a target="_blank" rel="noopener" href="https://segmentfault.com/u/dbkernel">https://segmentfault.com/u/dbkernel</a></td>
</tr>
<tr>
<td>掘金</td>
<td><a target="_blank" rel="noopener" href="https://juejin.im/user/5e9d3ed251882538083fed1f/posts">https://juejin.im/user/5e9d3ed251882538083fed1f/posts</a></td>
</tr>
<tr>
<td>开源中国（oschina）</td>
<td><a target="_blank" rel="noopener" href="https://my.oschina.net/dbkernel">https://my.oschina.net/dbkernel</a></td>
</tr>
<tr>
<td>博客园（cnblogs）</td>
<td><a target="_blank" rel="noopener" href="https://www.cnblogs.com/dbkernel">https://www.cnblogs.com/dbkernel</a></td>
</tr>
</tbody></table>

      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://dbkernel.github.io/2016/03/15/how-to-install-postgres-xc-on-linux/" title="最佳实践 | 源码编译安装配置 Postgres-XC 集群并用 pg_basebackup 配置 Datanode 热备" target="_blank" rel="external">http://dbkernel.github.io/2016/03/15/how-to-install-postgres-xc-on-linux/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN 许可协议</a>，转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://github.com/dbkernel" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="../../../../images/avatar.png" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://github.com/dbkernel" target="_blank"><span class="text-dark">DBKernel</span><small class="ml-1x">资深数据库开发工程师</small></a></h3>
        <div>目前从事云数据库MySQL/PostgreSQL的研发工作，曾做过PGXC、Greenplum等分布式数据库的内核开发。热衷于研究主流数据库架构、源码，对关系型数据库 MySQL/PostgreSQL及分布式数据库有深入研究。</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
           
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="../../30/postgresql-regression-test-details/" title="源码分析 | PostgreSQL 回归测试详解"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="../../../01/21/greenplum-primary-mirror-sync-mechanism/" title="特性分析 | GreenPlum Primary/Mirror 同步机制"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>赏</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,qzone,facebook,twitter,linkedin" data-mobile-sites="weibo,qq,wechat,qzone,linkedin"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>感谢您的支持，我会继续努力的!</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="../../../../images/donate/alipayimg.png" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开支付宝扫一扫，即可进行扫码打赏哦</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="../../../../images/donate/wechatpayimg.png" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开微信扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> 支付宝</a>
              </li>
              <li role="presentation" class="">
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> 微信支付</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="../../../../https:/github.com/dbkernel" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="../../../../atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        &copy; 2022 DBKernel
        
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="../../../../js/plugin.min.js"></script>


<script src="../../../../js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '../../../../content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="../../../../js/insight.js"></script>






   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





   
    
  <!-- <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css"> -->
  <script src="//cdn.jsdelivr.net/npm/gitalk@1.4.0/dist/gitalk.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/blueimp-md5@2.10.0/js/md5.min.js"></script>
  <script type="text/javascript">
  var gitalk = new Gitalk({
    clientID: '642675de9efee853bde8',
    clientSecret: 'e481d901d83ac31b4041437ec30a4fd00d112cfa',
    repo: 'dbkernel/gitalk-comment',
    owner: 'dbkernel',
    admin: ['dbkernel1989'],
    id: md5(location.pathname),
    distractionFreeMode: true
  })
  gitalk.render('comments')
  </script>

      






    <script defer>
var _hmt = _hmt || [];
(function() {
    var hm = document.createElement("script");
    hm.src = "//hm.baidu.com/hm.js?bf7f972e25b6a36ff4b828ba0214e515";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();
</script>



</body>
</html>